<template>
  <div class="page">
    <!-- 搜索区域 开始 -->
    <div class="el_card_box">
      <el-form :inline="true" size="small" :model="formInline" class="search_form">
        <el-form-item label="医院：">
          <hospital-select v-model="formInline.hospitals"></hospital-select>
        </el-form-item>
        <el-form-item label="医生：">
          <DoctorSelect v-model="formInline.doctors"></DoctorSelect>
        </el-form-item>
        <el-form-item label="商品：">
          <GoodsSelect v-model="formInline.goods"></GoodsSelect>
        </el-form-item>
        <el-form-item label="所属平台：">
          <PlatformSelect v-model="formInline.platforms"></PlatformSelect>
        </el-form-item>
        <el-form-item label="状态：">
          <shelf-select v-model="formInline.onShelf"></shelf-select>
        </el-form-item>
        <el-form-item label="关键词：">
          <el-input v-model="formInline.term" placeholder="请输入关键词"></el-input>
        </el-form-item>
      </el-form>
      <div class="search_btn_box">
        <el-button type="primary" size="small" @click="onSearch">筛选</el-button>
        <el-button type="default" size="small" @click="rest">清空筛选</el-button>
      </div>
    </div>
    <!-- 搜索区域 end -->

    <!-- 表格 开始 -->
    <div class="table_box">
      <!-- 操作区域 开始 -->
      <div class="action_box">
        <el-button type="primary" size="small" @click="addReview()">新增评论</el-button>
      </div>
      <!-- 操作区域 end -->

      <el-table ref="elTable" class="el_table" size="small" :data="tableData">
        <el-table-column prop="channelName" label="用户信息" width="180px">
          <template slot-scope="{row}">
            <ReviewUser :info="row"></ReviewUser>
          </template>
        </el-table-column>
        <el-table-column prop="content" label="评论对象" show-overflow-tooltip>
          <template slot-scope="{row}">
            <div v-if="row.hospitalName">{{ row.hospitalName }}</div>
            <div v-if="row.doctorName">{{ row.doctorName }}</div>
            <div v-if="row.goodsName">{{ row.goodsName }}</div>
          </template>
        </el-table-column>
        <el-table-column prop="receptionTel" label="评分">
          <template slot-scope="{row}">
            <div class="">
              <div>总体：{{ row.scoreOverall }}分</div>
              <div>专业：{{ row.scoreProfessional }}分</div>
              <div>服务：{{ row.scoreService }}分</div>
              <div>环境：{{ row.scoreSurroundings }}分</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column prop="content" label="点评内容" show-overflow-tooltip />
        <el-table-column prop="commentPics" label="点评图片" show-overflow-tooltip>
          <template slot-scope="{row}">
            <li-image v-for="(item, index) in getImages(row.commentPics)" :key="index" :src="item" class="tab_img"></li-image>
          </template>
        </el-table-column>
        <el-table-column prop="voucherPics" label="消费凭证" show-overflow-tooltip>
          <template slot-scope="{row}">
            <li-image v-for="(item, index) in getImages(row.voucherPics)" :key="index" :src="item" class="tab_img"></li-image>
          </template>
        </el-table-column>
        <el-table-column prop="platform" label="所属平台" show-overflow-tooltip />
        <el-table-column prop="createdDate" label="创建时间" show-overflow-tooltip />
        <el-table-column prop="orderTime" label="排序时间" show-overflow-tooltip />
        <el-table-column prop="onShelf" label="状态" show-overflow-tooltip>
          <template slot-scope="{row}"><shelf-format :value="row.onShelf"></shelf-format></template>
        </el-table-column>
        <el-table-column prop="address" label="操作" width="200px" align="center">
          <template slot-scope="{row}">
            <!-- <el-link type="primary" class="el_link" @click="updateInfo(row)">{{ row.onShelf == 1 ? '下架' : '上架' }}</el-link> -->
            <el-link type="primary" class="el_link" @click="addReview(row.id)">编辑</el-link>
            <el-link type="danger" class="el_link" @click="removeInfo(row)">删除</el-link>
          </template>
        </el-table-column>
      </el-table>
      <div class="pagination_list">
        <el-pagination background layout="sizes, total,prev, pager, next, jumper" :total="pageTotal" :page-size="pageSize" :page-sizes="pageSizes" :current-page.sync="pageNumber" @current-change="getList" @size-change="changePageSize" />
      </div>
    </div>
    <!-- 表格 end -->
  </div>
</template>

<script>
import { showToast, showModal, deepClone } from "@/common/util";
import { GET_COMMENT_SEARCH, DELETE_COMMENT_INFO, STARTSTOP_COMMENT_INFO } from '@/http/consumer'
import ReviewUser from '@/components/user/review.vue'
import DoctorSelect from '@/components/select/doctor.vue'
import PlatformSelect from '@/components/select/platform.vue'
import GoodsSelect from '@/components/select/goods.vue'
export default {
  components: {
    ReviewUser,
    DoctorSelect,
    PlatformSelect,
    GoodsSelect
  },
  data() {
    return {
      formInline: {},
      tableData: [],
      pageTotal: 0,
      pageNumber: 1,
      pageSizes: [10, 20, 50, 100],
      pageSize: 20,
      loading: false,
      cityList: [],
    };
  },
  mounted() {
    this.getList();
  },
  methods: {
    /** 重置 */
    rest() {
      this.formInline = {};
      this.getList();
    },

    /** 每页展示 */
    changePageSize(e) {
      this.pageSize = e;
      this.getList();
    },

    /** 获取参数 */
    getParams() {
      let oParams = JSON.parse(JSON.stringify(this.formInline));

      oParams.pageNumber = this.pageNumber;
      oParams.pageSize = this.pageSize;
      return oParams;
    },

    /** 获取列表 */
    getList() {
      let _this = this;
      let oParams = this.getParams();
      GET_COMMENT_SEARCH(oParams).then((res) => {
        let obj = res.data || {};
        _this.tableData = obj.list || [];
        _this.pageTotal = obj.totalElements;
      });
    },

    // 新增医院
    addReview(id) {
      this.$router.push({ name: "consumerReviewAdd", query: { id: id } });
    },

    // 格式化医院数据
    showFormatter(row) {
      if (!row) {
        return {};
      }
      let o = deepClone(row)
      o.customerName = row.reviewer;
      o.customerPhone = row.reviewerPhone;
      return o;
    },

    // 删除
    removeInfo(row) {
      let _this = this;
      showModal({
        message: `确定删除该条数据吗？`,
        showCancelButton: true,
        success: function () {
          DELETE_COMMENT_INFO({ id: row.id }).then((res) => {
            if (res.code == 200) {
              showToast({
                message: "删除成功",
                type: "success",
              });
              _this.getList();
            }
          });
        },
      });
    },

    // 上下架
    updateInfo(row) {
      let _this = this;
      showModal({
        message: `确认${row.onShelf == 1 ? "下架" : "上架"}该评论吗？`,
        showCancelButton: true,
        type: "warning",
        success: function () {
          STARTSTOP_COMMENT_INFO({ id: row.id }).then((res) => {
            if (res.code == 200) {
              showToast({
                message: "操作成功",
                type: "success",
              });
              _this.getList();
            }
          });
        },
      });
    },

    // 获取图片
    getImages(str) {
      if (!str || str.length <= 0) {
        return []
      }
      let arr = []
      if (typeof str == 'object') {
        arr = str
        return arr
      }

      arr = str.split(',')
      return arr;
    },

    // 搜索
    onSearch(){
      this.pageNumber = 1;
      this.getList()
    }

  },
};
</script>

<style lang="scss" scoped>
@import "@/assets/style/customer/index.scss";

.tab_img {
  width: 30px;
  height: 30px;
  margin: 2px;
}
</style>
